package com.igame.mapper;

import com.github.pagehelper.Page;
import com.igame.dto.GoodsDao;
import com.igame.dto.GoodsPageQueryDto;
import com.igame.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper {
    Page<Goods>pageQuery(GoodsPageQueryDto goodsPageQueryDto);

    List<Goods> goodsList(GoodsDao goodsDao);

    @Select("select * from goods where id=#{id}")
    Goods getGoodsById(int id);

    @Insert("insert into shopping_cart(id, user_id, goods_id) values (#{id},#{userId},#{goodsId})")
    int insert(ShoppingCart shoppingCart);

    @Select("select * from  shopping_cart where user_id=#{userId} and goods_id=#{goodsId}")
    ShoppingCart isInCar(Integer userId,Integer goodsId);

    @Select("SELECT goods_id from shopping_cart where user_id =#{userId}")
    List<Integer> findCar(Integer userId);

    @Delete("delete from shopping_cart where user_id=#{userId} and goods_id =#{goodsId}")
    int deleteCarGoods(Integer userId,Integer goodsId);

    @Select("SELECT * from goods where create_user = #{name}")
    List<Goods> selectByUserName(String name);

    @Select("SELECT * from goods where create_user = #{name} and state = 1")
    List<Goods> selectByUserNameAndState(String name);

    @Select("SELECT * from free_post")
    List<FreePost> selectAllFreePost();

    @Select("SELECT * from fineness")
    List<Fineness> selectAllFineness();

    @Select("SELECT * from pack")
    List<Pack> selectAllPack();

    @Select("SELECT * from version")
    List<Version> selectAllVersion();


    @Select("SELECT * from platform")
    List<Platform> selectAllPlatform();


    @Insert("insert into goods(id, name, img_path, price, blurb, intro, categories_id, platform, create_time, update_time, create_user, update_user, free_post, version, fineness, packa, state) VALUES(#{id},#{name},#{imgPath},#{price},#{blurb},#{intro},#{categoriesId},#{platform},#{createTime},#{updateTime},#{createUser},#{updateUser},#{freePost},#{version},#{packa},#{fineness},#{state})")
    int insertGoods(Goods goods);
//    获取最新id
    @Select("SELECT id FROM goods  ORDER BY id DESC LIMIT 1")
    Integer selectNewId();

    @Update("update goods set state = #{state} where id =#{goodsId}")
    int setGoodsState(Integer goodsId,Integer state);

}
